package leetcode;

public class Leetcode468 {
    public String validIPAddress(String IP) {
        String ipv4 = "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
        String ipv6 = "([0-9a-fA-F]{1,4}\\.){7}[0-9a-fA-F]{1,4}";
        if(IP.contains(".")){
            return IP.matches(ipv4)?"IPv4" : "Neither";
        }
        if(IP.contains(":")){
            return IP.matches(ipv6)?"IPv6" : "Neither";
        }
        return "Neither";
    }
}
